// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   BAGCommonImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

//import oracle.xml.parser.v2.XMLDocument;
//import oracle.xml.parser.v2.XMLNode;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, INTImpl, NullFlavorImpl

public abstract class BAGCommonImpl extends ANYImpl
{

    public static final String RCS_ID = "$Header: BAGCommonImpl.java 115.26 2005/07/13 15:04:04 pkiran noship $";
    protected List mList;

    @SuppressWarnings("rawtypes")
	protected BAGCommonImpl(List list)
    {
        mList = new ArrayList();
        if((list == null || !verifyList(list)) && list == null)
        {
            throw ANYImpl.newNullException("BAG", "constructor", "list");
        } else
        {
            mList.addAll(list);
            return;
        }
    }

    protected BAGCommonImpl(CS cs)
    {
        super(true, cs);
        mList = new ArrayList();
        mList = null;
    }

    protected BAGCommonImpl()
    {
        mList = new ArrayList();
    }

    protected INT containsANY(ANY any)
    {
        if(isNull().or(any.isNull()).isTrue())
            return INTImpl.nullINT(NullFlavorImpl.NI);
        int i = 0;
        for(int j = 0; j < mList.size(); j++)
        {
            ANY any1 = (ANY)mList.get(j);
            if(any1.equal(any).isTrue())
                i++;
        }

        return INTImpl.valueOf(i);
    }

    protected List plus(List list, List list1)
    {
        ArrayList arraylist = new ArrayList(list);
        ArrayList arraylist1 = new ArrayList(list1);
        arraylist.addAll(arraylist1);
        return arraylist;
    }

    protected List minus(List list, List list1)
    {
        ArrayList arraylist = new ArrayList(list);
        ArrayList arraylist1 = new ArrayList(list1);
        for(Iterator iterator = arraylist1.iterator(); iterator.hasNext();)
        {
            ANY any = (ANY)iterator.next();
            int i = arraylist.indexOf(any);
            if(i >= 0)
                arraylist.remove(i);
        }

        return arraylist;
    }

    protected List promoteItem(ANY any)
    {
        ArrayList arraylist = new ArrayList();
        arraylist.add(any);
        return arraylist;
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.TRUE;
        else
            return BLImpl.valueOf(mList.isEmpty());
    }

    public BL notEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.FALSE;
        else
            return isEmpty().not();
    }

    public List toList()
    {
        if(isNull().isTrue())
            return null;
        else
            return Collections.unmodifiableList(mList);
    }

    protected abstract boolean verifyItem(Object obj);

    protected boolean verifyList(List list)
    {
        boolean flag = true;
        for(Iterator iterator = list.iterator(); flag && iterator.hasNext(); flag = verifyItem(iterator.next()));
        return flag;
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        int i = 0;
//        try
//        {
//            Vector vector = new Vector();
//            for(Iterator iterator = toList().iterator(); iterator != null && iterator.hasNext();)
//            {
//                Object obj = iterator.next();
//                if((obj instanceof ANYImpl) && ((ANYImpl)obj).isNull().isFalse())
//                {
//                    i++;
//                    vector.add(((ANYImpl)obj).writeXML(xmldocument, s)[0]);
//                }
//            }
//
//            return (XMLNode[])vector.toArray(new XMLNode[i]);
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }
}
